﻿// Developer Express Code Central Example:
// World Wide CRM Demo
// 
// The World Wide CRM demo is a next generation application with outstanding
// navigation capabilities and shows a reimagined view of customer contact and
// management. This demo showcases many of the most popular features of the
// WinForms Subscription.
// 
// You can find sample updates and versions for different programming languages here:
// http://www.devexpress.com/example=E3993

using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace DevExpress.CrmDemo.Win.Helpers
{
    public static class DataBindingHelpers
    {
        public static void SuspendTwoWayBinding(BindingManagerBase bindingManager)
        {
            if (bindingManager == null)
            {
                throw new ArgumentNullException("bindingManager");
            }

            foreach (Binding b in bindingManager.Bindings)
            {
                b.DataSourceUpdateMode = DataSourceUpdateMode.Never;
            }
        }

        public static void UpdateDataBoundObject(BindingManagerBase bindingManager, BindingSource bindingSource)
        {
            if (bindingManager == null)
            {
                throw new ArgumentNullException("bindingManager");
            }

            bindingSource.RaiseListChangedEvents = false;

            foreach (Binding b in bindingManager.Bindings)
            {
                b.WriteValue();
            }

            bindingSource.RaiseListChangedEvents = true;
        }
    }
}